<?php
/**
 * Created by PhpStorm.
 * User: 王峥宇
 * Date: 2019-04-28
 * Time: 8:42
 */

namespace app\admin\model;


class Indentqx extends BaseModel
{
    protected $table='jc_indent_qx';

    //支付方式
    public function zPayType(){
        return $this->belongsTo('Zpaytype','zid','zid');
    }
    //会员
    public function iUser(){
        return $this->belongsTo('User','uid','uid');
    }
    //取消订单显示
    public static function getIndentQx(){
        $where=[];
        if(input('sub')){
            $cateid = input('cateid');
            $zid = input('zid');
            $key = input('key');
            $datemin = input('datemin', '');//最小时间
            $datemax = input('datemax', '');//最大的吧
            if (isset($datemin) && $datemin != '') {
                $where['z_createtime']=['>=', $datemin . ' 00:00:00'];
            }
            if (isset($datemax) && $datemax != '') {
                $where['z_createtime']=['<=', $datemax . ' 23:59:59'];
            }
            if($zid != ''){
                $where['zid']=[
                    'like',
                    '%'.$zid.'%'
                ];
            }
            if($cateid=='t_number'){
                $where['t_number']=[
                    'like',
                    '%'.$key.'%'
                ];
            }else if($cateid=='z_name'){
                $where['z_name']=[
                    'like',
                    '%'.$key.'%'
                ];
            }
            $arr=self::with('zPaytype,iUser')->where($where)->order('tid','desc')->paginate(12);
            return $arr;
        }
        $arr=self::with('zPaytype,iUser')->order('tid','desc')->paginate(12);
        return $arr;
    }
    //删除订单
    public static function getIndentQxDel(){
        $tid = input('tid');
        $del = self::where('tid',$tid)->delete();
        if ($del){
            return 1;
        }else{
            return 2;
        }
    }
}